<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <div id="app">
    <button @click="isShow=!isShow">{{isShow?'隐藏':'显示'}}</button>
    <common-head v-if="isShow"></common-head>
  </div>
  <script src="./vue.js"></script>
  <script>
  
    const CommonHead = {
      template: `
        <div>
          <h1>我是公共头部</h1>  
          <button @click="addLi">按钮</button>
          <ul>
            <li v-for="item in arr" :key="item">
              {{ item }}  
            </li>  
          </ul>
        </div>
        
      `,
      data(){
        return {
          arr: [1,2,3,4]
        }
      },
      methods: {
        addLi(){
          this.arr.push(this.arr.length+1)
        }
      },
      beforeCreate(){
        console.log('实例加载完成之前-beforeCreate');
      },
      created () {
        console.log('实例已经加载完成-created');
      },
      beforeMount () {
        console.log('虚拟已经编译完成-beforeMount');
      },
      mounted () {
        console.log('真实dom编译完成-mounted');;
      },
      beforeUpdate () {
        console.log('数据更新之前-beforeUpdate');;
      },
      updated () {
        console.log('数据更新dom更新完成-updated');;
      },
      beforeDestroy () {
        console.log('组件卸载之前');;
      },
      destroyed () {
        console.log('组件卸载完成');;
      },
    };
    Vue.component('CommonHead', CommonHead)
    const vm = new Vue({
      el: '#app',
      data: {
        isShow: true
      }
    })
  </script>
</body>
</html>